package com.wuzu.ecommerce.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuzu.ecommerce.entity.Integral;
import com.wuzu.ecommerce.service.IntegralService;
import com.wuzu.ecommerce.utils.R;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 积分规则(Integral)表控制层
 *
 * @author jsm
 * @since 2023-03-26 17:25:21
 */
@RestController
@RequestMapping("/api/integral")
@Api(tags = "Integral CRUD")
public class IntegralController {

    /**
     * 服务对象
     */
    @Resource
    private IntegralService integralService;

    /**
     * 查询所有数据
     */
    @ApiOperation("查询所有数据")
    @GetMapping("/all")
    public R all() {
        return R.ok(integralService.list());
    }


    /**
     * 分页查询所有数据
     */
    @ApiOperation("分页查询")
    @GetMapping
    public R page(@RequestParam int current, @RequestParam int size) {
        Page<Integral> page = new Page<>(current, size);
        return R.ok(integralService.page(page));
    }


    /**
     * 通过主键查询单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("/{id}")
    public R selectOne(@PathVariable Serializable id) {
        return R.ok(integralService.getById(id));
    }

    /**
     * 新增数据
     */
    @ApiOperation("新增数据")
    @PostMapping
    public R save(@RequestBody Integral integral) {
        return R.ok(integralService.save(integral));
    }

    /**
     * 修改数据
     */
    @ApiOperation("修改数据")
    @PutMapping
    public R updateById(@RequestBody Integral integral) {
        return R.ok(integralService.updateById(integral));
    }

    /**
     * 单条/批量删除数据
     */
    @ApiOperation("单条/批量删除数据")
    @DeleteMapping
    public R delete(@RequestParam List<Long> id) {
        return R.ok(integralService.removeByIds(id));
    }
}
